<?php

namespace app\admin\model;

use Illuminate\Database\Eloquent\Relations\BelongsTo;
use support\Model;

/**
 * 行为日志模型
 * @property int $id
 * @property int $admin_id 管理员ID
 * @property string $admin_name 管理员名称
 * @property string $url 请求URL
 * @property string $ip IP地址
 * @property string|null $user_agent User Agent
 * @property string|null $request_data 请求数据
 * @property string|null $response_data 响应数据
 * @property int|null $execution_time 执行时间(毫秒)
 * @property int $status 状态:0=失败,1=成功
 * @property string $create_time 创建时间
 */
class ActionLog extends Model
{
    /**
     * The table associated with the model.
     * @var string
     */
    protected $table = 'action_log';
    /**
     * The primary key associated with the table.
     * @var string
     */
    protected $primaryKey = 'id';
    /**
     * Indicates if the model should be timestamped.
     * @var bool
     */
    public $timestamps = true;
    /**
     * The name of the "created at" column.
     * @var string|null
     */
    const CREATED_AT = 'create_time';
    /**
     * The name of the "updated at" column.
     * @var string|null
     */
    const UPDATED_AT = null;
    /**
     * The attributes that are mass assignable.
     * @var array
     */
    protected $fillable = [
        'admin_id',
        'admin_name',
        'url',
        'ip',
        'user_agent',
        'request_data',
        'response_data',
        'execution_time',
        'status',
    ];
    /**
     * The attributes that should be cast to native types.
     * @var array
     */
    protected $casts = [
        'admin_id' => 'integer',
        'execution_time' => 'integer',
        'status' => 'integer',
        'create_time' => 'datetime:Y-m-d H:i:s',
    ];

    /**
     * 获取日志关联的管理员
     */
    public function admin(): BelongsTo
    {
        return $this->belongsTo(Admin::class, 'admin_id', 'id');
    }
}